﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Scrabble.Model
{
    public static class Extensions
    {
        public static IList<T> Shuffle<T>(this IList<T> t, Func<int, int> random)
        {
            for (var i = t.Count; i > 0; )
            {
                var j = random(i--);

                var temp = t[i];
                t[i] = t[j];
                t[j] = temp;
            }

            return t;
        }

        public static IEnumerable<BoardLocation> AvailableLocationsIn(this Board board, PlayVector vector)
        {
            return vector.Locations.Where(location => !board.TileExistsAt(location));
        }

        public static void AddRange<T>(this ICollection<T> collection, IEnumerable<T> items)
        {
            foreach (var item in items)
            {
                collection.Add(item);
            }
        }
    }
}